package m.jclecai.com.view.common;

import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;


import m.jclecai.com.R;
import m.jclecai.com.view.klpk.CheckedImageView;
import q.rorbin.badgeview.Badge;
import q.rorbin.badgeview.QBadgeView;

/**
 * Created by andy on 2017/6/21.
 * 这个是专门用来实现底部的
 * 底部的一个title bar；
 */

public class BottomBar extends LinearLayout {
    private View mView;
    private TextView mTvRandomChoose;
    private CheckedImageView mIvBettingArea;
    private TextView mTvNext;
    private Badge mBadge;


    public BottomBar(Context context) {
        this(context,null);
    }

    public BottomBar(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public BottomBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        //这里
        mView = View.inflate(context, R.layout.bar_bottom,this);
        setOrientation(LinearLayout.VERTICAL);
        mTvRandomChoose = ((TextView) mView.findViewById(R.id.tv_random_choose));
        mIvBettingArea = (CheckedImageView)mView.findViewById(R.id.iv_betting_area);
        mTvNext = (TextView)mView.findViewById(R.id.tv_next);

        mBadge = new QBadgeView(context).bindTarget(mIvBettingArea);

        mBadge.setBadgeGravity(Gravity.TOP| Gravity.END);
        mBadge.setGravityOffset(1,0,true);
        mBadge.setBadgeTextSize(12,true);
        mBadge.setBadgePadding(2,true);
    }

    public void setBettingNumber(int number){
        mBadge.setBadgeNumber(number);
    }

    public void setChecked(boolean isChecked){
        mIvBettingArea.setChecked(isChecked);
    }

    /**
     * 这个是设置小红点拖动的事件；
     * @param onDragstateChangeListener
     */
    public void setOnDragstateChangeListener(Badge.OnDragStateChangedListener onDragstateChangeListener){
        mBadge.setOnDragStateChangedListener(onDragstateChangeListener);
    }

    public void setLeftButtonText(String string){
        mTvRandomChoose.setText(string);
    }

    public void setLeftButtonText(int strRes){
        mTvRandomChoose.setText(strRes);
    }
    public void setRightButtonText(String string){
        mTvRandomChoose.setText(string);
    }

    public void setRightButtonText(int strRes){
        mTvRandomChoose.setText(strRes);
    }

    public void setCenterButtonClickListener(OnClickListener onClickListener){
        mIvBettingArea.setOnClickListener(onClickListener);
    }

    public void setLeftButtonClickListener(OnClickListener onClickListener){
        mTvRandomChoose.setOnClickListener(onClickListener);
    }

    public  void setRightButtonClickListener(OnClickListener onClickListener){
        mTvNext.setOnClickListener(onClickListener);
    }

    public void setLeftText(String text) {
        mTvRandomChoose.setText(text);
    }

    public String getLeftText() {
       return mTvRandomChoose.getText().toString();
    }

}
